package br.com.dubs.persistence.entities;

import java.io.Serializable;
import java.util.SortedSet;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;

import br.com.dubs.persistence.entities.comparators.MsgEntityComparator;

@Entity
public class ClientEntity implements Serializable {
	@Id
	@GeneratedValue
	private Integer id;
	@Column(nullable=false)
	private String login;
	@Column(nullable=false)
	private String password;
	@Column(nullable=false)
	private String name;
	@Column(nullable=false)
	private String email;
	@OneToOne(mappedBy = "client", fetch = FetchType.EAGER)
	private Contacts contactList;

	@OneToMany(mappedBy = "receiver", fetch = FetchType.EAGER,cascade=CascadeType.ALL)
	@Sort(type = SortType.COMPARATOR, comparator = MsgEntityComparator.class)
	private SortedSet<MsgEntity> receivedMsg;

	@OneToMany(mappedBy = "sender", fetch = FetchType.EAGER,cascade=CascadeType.ALL)
	@Sort(type = SortType.COMPARATOR, comparator = MsgEntityComparator.class)
	private SortedSet<MsgEntity> sentMsg;

	public ClientEntity() {
		sentMsg = new TreeSet<MsgEntity>(new MsgEntityComparator());
		receivedMsg = new TreeSet<MsgEntity>(new MsgEntityComparator());
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public SortedSet<MsgEntity> getReceivedMsg() {
		return receivedMsg;
	}

	public void setReceivedMsg(SortedSet<MsgEntity> receivedMsg) {
		this.receivedMsg = receivedMsg;
	}

	public SortedSet<MsgEntity> getSentMsg() {
		return sentMsg;
	}

	public void setSentMsg(SortedSet<MsgEntity> sentMsg) {
		this.sentMsg = sentMsg;
	}

	public Contacts getContactList() {
		return contactList;
	}

	public void setContactList(Contacts contactList) {
		this.contactList = contactList;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

}
